﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Data;

namespace PracticeProject
{
    public partial class Adding_Form : Form
    {
        public Goal goal;
        int parentGoal = 0;
        public Adding_Form()
        {
            InitializeComponent();
            CmbPriority.SelectedIndex = 1;
        }
        public Adding_Form(int id)
        {
            InitializeComponent();
            parentGoal = id;
        }
        public Adding_Form(Goal g)
        {
            InitializeComponent();
            goal = g;
            TxtDesc.Text = goal.Description;
            TxtComments.Text = goal.Comments;
            DateExpectingTime.Value = goal.ExpectedEndingTime;
            CmbPriority.SelectedIndex = goal.Priority;
            btnAdd.Text = "Edit";
        }

        private void Adding_Form_KeyDown(object sender, KeyEventArgs e)
        {
            if ((e.KeyCode == System.Windows.Forms.Keys.Up))
            {
                // Up
            }
            if ((e.KeyCode == System.Windows.Forms.Keys.Down))
            {
                // Down
            }
            if ((e.KeyCode == System.Windows.Forms.Keys.Left))
            {
                // Left
            }
            if ((e.KeyCode == System.Windows.Forms.Keys.Right))
            {
                // Right
            }
            if ((e.KeyCode == System.Windows.Forms.Keys.Enter))
            {
                // Enter
            }

        }

        private void menuItem3_Click(object sender, EventArgs e)
        {

        }

        private void menuItem2_Click(object sender, EventArgs e)
        {

        }

        

        private void btnAdd_Click(object sender, EventArgs e)
        {
            ElementCollection elements = ElementCollection.OpenCollectionFromXml();
            if (goal == null)
                elements.AddGoal(TxtDesc.Text, TxtComments.Text, DateExpectingTime.Value, CmbPriority.SelectedIndex, parentGoal);
            else
            {
                goal.Description = TxtDesc.Text;
                goal.Comments = TxtComments.Text;
                goal.ExpectedEndingTime = DateExpectingTime.Value;
                goal.Priority = CmbPriority.SelectedIndex;
                elements.EditGoal(goal);
            }
            elements.SaveCollectionToXml();
        }

        private void Adding_Form_Load(object sender, EventArgs e)
        {

        }
    }
}